/**
 * Created by benz on 2017/3/19.
 */
module.exports = app => {
    const Sequelize = app.Sequelize;
    return app.model.define('article', {
        id:{
            type:Sequelize.INTEGER,
            autoIncrement:true,
            allowNull:false,
            primaryKey:true,
            unique:true
        },
        userId:{
            type:Sequelize.INTEGER,
            allowNull:false
        },
        title: {

            type:Sequelize.STRING,
            allowNull:false
        },
        menuId: {
            type:Sequelize.INTEGER,
            allowNull:false,
        },
        remark: {
            type:Sequelize.STRING,
            allowNull:true
        },
        content:{
            type:Sequelize.TEXT,
            allowNull:false,

        },
        views:{
            type:Sequelize.INTEGER,
            allowNull:false,
            defaultValue:0

        }
    },{
        timestamps:true,
        paranoid:true,
        underscored: false,
        classMethods: {
            associate() {
                app.model.Article.belongsTo(app.model.User);
                app.model.Article.belongsTo(app.model.Menu);
                app.model.Article.belongsToMany(app.model.Label, {through: 'article_has_label', foreignKey: 'articleId'});
            }
        }
    });
};